<?php

function mysql_get_username ($userid) {
	$result = mysql_query("SELECT * FROM user WHERE user_id = $userid");
	if ($row = mysql_fetch_array($result)) { return $row['username']; } else { return ''; }
}

function mysql_get_usertype ($username) {
	global $main_acc;
	if (isset($main_acc[$username])){
		return 'admin';
	} else {
		return 'user';
	}
}

function mysql_get_newid($table, $field) {
	$result = mysql_query("SELECT MAX($field) AS old_id FROM $table");
	if ($result){
		$row = mysql_fetch_array($result);
		return $row['old_id'] + 1;
	} else {
		return 1;	
	}
}

function mysql_count($table) {
	$result = mysql_query("SELECT COUNT(*) AS num FROM $table");
	if ($result){
		$row = mysql_fetch_array($result);
		return $row['num'];
	} else {
		return 0;	
	}
}

function check_permission($usertype) {
	$a = array('guest' => 0, 'user' => 1, 'admin' => 2);
	return $a[$_SESSION['usertype']] >=  $a[$usertype];
}

?>